package com.pan.kang;


import java.util.EventObject;
import java.util.HashSet;
import java.util.Set;

public class EventPublisher implements Publisher {

    /**
     * 存储订阅者列表
     */
    private Set<Subscriber<EventObject>> subscribers = new HashSet<>();

    /**
     * 添加
     *
     * @param e 订阅者
     * @return true
     */
    @Override
    public Set<Subscriber<EventObject>> add(Subscriber<EventObject> e) {
        subscribers.add(e);
        return subscribers;
    }

    /**
     * 移除
     *
     * @param e 订阅者
     * @return true
     */
    @Override
    public Set<Subscriber<EventObject>> remove(Subscriber<EventObject> e) {
        subscribers.remove(e);
        return subscribers;
    }

    public Set<Subscriber<EventObject>> getSubscribers() {
        return subscribers;
    }

    public void setSubscribers(Set<Subscriber<EventObject>> subscribers) {
        this.subscribers = subscribers;
    }
}
